<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- 外部样式-->
<link rel="stylesheet" type="text/css" href="../CSS/UserRegister.css" />
	
<script type="text/javascript">
    //定义了城市的二维数组，里面的顺序跟省份的顺序是相同的。通过selectedIndex获得省份的下标值来得到相应的城市数组 
    var arraycity = [ [ "北京", "天津", "上海", "重庆", "香港", "澳门" ], [ "南京", "苏州", "扬州", "无锡", "徐州", "常州", "南通", "连云港", "淮安", "盐城", "镇江", "泰州", "宿迁" ],
            [ "杭州", "宁波", "温州", "嘉兴", "湖州", "绍兴", "金华", "衢州", "舟山", "台州", "丽水" ] ];
    function getCity() {
        //利用元素的ID属性，获得省份下拉框的对象 
        var sltProvince = document.getElementById("HomePlace");
        //获得城市下拉框的对象 
        var sltCity = document.getElementById("UserCity");
        //得到对应省份的城市数组 
        var provinceCity = arraycity[sltProvince.selectedIndex - 1];
        //清空城市下拉框，仅留提示选项 
        sltCity.length = 1;
        //将城市数组中的值填充到城市下拉框中 
        for (var i = 0; i < provinceCity.length; i++) {
            sltCity[i + 1] = new Option(provinceCity[i], provinceCity[i]);
        }
    }
    function  UserCode() {
		if(document.getElementById("userDTO.userLoginName").value=="不能输入特殊字符")	
			document.getElementById("userDTO.userLoginName").value="";
	}
   
    function logincheck(){
    	if(document.getElementById("userDTO.userLoginName").value=="")
		{
			alert("用户名不能为空");
			document.getElementById("userDTO.userLoginName").focus();
			return false;
		}
    	else if(document.getElementById("userDTO.userPwd").value==""){
    		alert("密码不能为空");
			document.getElementById("userDTO.userPwd").focus();
    		return false;
    	}
    	else if(document.getElementById("ConfirmPwd").value==""){
    		alert("确认密码不能为空");
			document.getElementById("ConfirmPwd").focus();
			return false;
    	}
    	else{
    		
    		return true;
    	}
    }

    function CheckPwd() {
		var reg=new RegExp(/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/);
		var pwd=document.getElementById("userDTO.userPwd").value;
		if(pwd){
			if(!reg.test(document.getElementById("userDTO.userPwd").value))
			{
				alert("密码格式不正确");
				document.getElementById("userDTO.userPwd").value="";
				document.getElementById("userDTO.userPwd").focus();
			}
		}
	}
    function CheckPwd1() {
    	var reg=new RegExp(/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/);
		var pwd=document.getElementById("userDTO.userPwd").value;
		var confirm=document.getElementById("ConfirmPwd").value;
		if(pwd&&confirm){
			if(pwd==confirm){
				
			}
			else{
				alert("两次输入密码不同");
				document.getElementById("ConfirmPwd").value="";
				document.getElementById("ConfirmPwd").focus();
			}
		}
	}
    
    
</script>
<title>注册页面</title>
</head>
<body>
    <div align="center">
        <form  id="opForm"  method="post" action="../user/addUser.action" onsubmit="return logincheck()">
        
            <table border="0" width="600" height="80">
            	
                <tr>
                    <td width="50%" align="left" colspan="2"><p>用户注册账号</p></td>
                </tr>
            </table>
            <table class="registerTable" width="600">
                <tr>
                    <td width="30%" align="right" height="60">
                        <p class="defaultText">用户名：</p>
                    </td>
                    <td width="70%" align="left"><input class="registerText" value="不能输入特殊字符"
                        name="userDTO.userLoginName" id="userDTO.userLoginName" type="text"  onblur="checkName()"onfocus="UserCode()" >
                        <input type="hidden" value="add" name="userDTO.OnType" id="Ontype"/></td>
                        <span id="wirteHelp1"></span>
                </tr>
                <tr>
                    <td align="right" height="60">
                        <p class="defaultText">设置密码：</p>
                        
                    </td>
                    <td align="left"><input class="registerText" name="userDTO.userPwd" id="userDTO.userPwd" type="password" value="" onblur="CheckPwd()" >
                    <span class="tp_txt"  >密码必须包含数字和字母</span></td>
                </tr>
                <tr>
                    <td align="right" height="60">
                        <p class="defaultText">确认密码：</p>
                    </td>
                    <td align="left"><input class="registerText" id="ConfirmPwd"
                        name="ConfirmPwd" type="password" value="" onblur="CheckPwd1()">
                        <span class="tp_txt"  >请确认两次密码输入相同</span></td>
                </tr>
                <tr>
                    <td align="right" height="60">
                        <p class="defaultText">性别：</p>
                    </td>
                    <td align="left"><input id="userDTO.userSex" name="userDTO.userSex" type="radio"
                        value="1"><span class="defaultText">男</span> <input
                        id="userDTO.userSex" name="userDTO.userSex" type="radio" value="2"><span
                        class="defaultText">女</span></td>
                </tr>
               
                
                <tr>
                    <td align="right" height="60">
                        <p class="defaultText">真实姓名：</p>
                    </td>
                    <td align="left">
							<input type="text" name="userDTO.userName" id="userDTO.userName" class=""/>
                    </td>
                </tr>
                
                <tr>
                    <td align="right" height="60">
                        <p class="defaultText">联系电话：</p>
                    </td>
                    <td align="left">
						<input type="text" name="userDTO.userPhone" id="userDTO.userPhone" class=""/>
						</td>
                </tr>
                
                 <tr>
                    <td align="right" height="60">
                        <p class="defaultText">邮箱：</p>
                    </td>
                    <td align="left">
						<input type="text" name="userDTO.userMailBox" id="userDTO.userMailBox" class=""/>
						</td>
                </tr>
                
                <tr>
                    <td align="center" height="60"> </td>
                    <td align="left" height="60"><input class="registerButton"
                        id="registerUser" name="registerUser" type="submit" value="立即注册" ></td>
                </tr>
            </table>
        </form>
        <p style="font-family: 幼圆; font-size: 15px; color: gray;">版权所有 © 2014-2015
            YY招聘网</p>
    </div>
    
    <script>
    	function checkName(){
    		//定义一些全局变量
    		var nameState;
    		
    		var nameMark;				//nameMark==1登录名已经重复，nameState==fail 不能提交，nameMark==0,nameState==success
    		
    		var wordHelp = document.getElementById("wirteHelp1");		//状态
    		
    		var userName = document.getElementById("userDTO.userLoginName").value;
    		
    		function fName(name){
    			if(name[0] == "f"){
    				nameMark = 1;
    			}
    			else{
    				nameMark = 0;
    			}
    			if(nameMark == 0){
    				wordHelp.innerHTML = "";
    			}
    			else{
    				wordHelp.innerHTML = "用户名已经存在";
    			}
    		}
    		var request = new XMLHttpRequest();									  //XmlHttpRequest对象
    		var url = "../user/checkUser.action?userDTO.userLoginName="+userName; //设置URL
    		request.open("GET",url);
    		request.onreadystatechange = function(){							  //定义事件处理程序
    			if(request.readyState === 0){
    				//alert("open()尚未调用");
    			}
    			if(request.readyState === 1){
    				//alert("open()已经调用");
    			}
    			if(request.readyState === 2){
    				//alert("接收到头信息");
    			}
    			if(request.readyState === 3){
    				//alert("接收到响应主体");
    			}
    			if(request.readyState===4 && request.status===200){
    				var type = request.getResponseHeader("Content-Type");
    				if(type.indexOf("xml")!==-1 && request.responseXML){		//Document对象响应
    					alert("yesss");
    				}
    				else if(type === "application/json"){						//JSON响应	
    					alert("000000000");
    				}
    				else{														//字符串响应
    					nameState = request.responseText;
    					fName(nameState);
    				}
    			}
    		};
    		request.send();
    	}
    </script>
</body>

<script>
</script>
</html>